package com.ruoyi.web.controller.golang;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DictCity;
import com.ruoyi.system.service.IDictCityService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 省市区编码Controller
 * 
 * @author ruoyi
 * @date 2025-01-12
 */
@Controller
@RequestMapping("/system/city")
public class DictCityController extends BaseController
{
    private String prefix = "system/city";

    @Autowired
    private IDictCityService dictCityService;

    @RequiresPermissions("system:city:view")
    @GetMapping()
    public String city()
    {
        return prefix + "/city";
    }

    /**
     * 查询省市区编码列表
     */
    @RequiresPermissions("system:city:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DictCity dictCity)
    {
        startPage();
        List<DictCity> list = dictCityService.selectDictCityList(dictCity);
        return getDataTable(list);
    }

    /**
     * 导出省市区编码列表
     */
    @RequiresPermissions("system:city:export")
    @Log(title = "省市区编码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DictCity dictCity)
    {
        List<DictCity> list = dictCityService.selectDictCityList(dictCity);
        ExcelUtil<DictCity> util = new ExcelUtil<DictCity>(DictCity.class);
        return util.exportExcel(list, "省市区编码数据");
    }

    /**
     * 新增省市区编码
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存省市区编码
     */
    @RequiresPermissions("system:city:add")
    @Log(title = "省市区编码", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DictCity dictCity)
    {
        return toAjax(dictCityService.insertDictCity(dictCity));
    }

    /**
     * 修改省市区编码
     */
    @RequiresPermissions("system:city:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        DictCity dictCity = dictCityService.selectDictCityById(id);
        mmap.put("dictCity", dictCity);
        return prefix + "/edit";
    }

    /**
     * 修改保存省市区编码
     */
    @RequiresPermissions("system:city:edit")
    @Log(title = "省市区编码", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DictCity dictCity)
    {
        return toAjax(dictCityService.updateDictCity(dictCity));
    }

    /**
     * 删除省市区编码
     */
    @RequiresPermissions("system:city:remove")
    @Log(title = "省市区编码", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dictCityService.deleteDictCityByIds(ids));
    }
}
